package org.groupg.practice.guava;

import com.google.common.base.Splitter;
import java.util.List;

public class SplitterExample {

    public static void main(String[] args) {
        // 示例 1: 按特定字符分割
        String input1 = "apple,banana,orange";
        List<String> result1 = Splitter.on(',')
                                       .splitToList(input1);
        System.out.println("示例 1: " + result1); // 输出: [apple, banana, orange]

        // 示例 2: 按字符串分割
        String input2 = "apple::banana::orange";
        List<String> result2 = Splitter.on("::")
                                       .splitToList(input2);
        System.out.println("示例 2: " + result2); // 输出: [apple, banana, orange]

        // 示例 3: 忽略空字符串
        String input3 = "apple,,banana,,orange";
        List<String> result3 = Splitter.on(',')
                                       .omitEmptyStrings()
                                       .splitToList(input3);
        System.out.println("示例 3: " + result3); // 输出: [apple, banana, orange]

        // 示例 4: 限制分割结果的数量
        String input4 = "apple,banana,orange,grape";
        List<String> result4 = Splitter.on(',')
                                       .limit(3)
                                       .splitToList(input4);
        System.out.println("示例 4: " + result4); // 输出: [apple, banana, orange,grape]
    }
}